﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;

namespace CSMF
{
    public partial class SearchMerak : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string title = txtSearch.Text.Trim();
                if (Session["SearchTitle"] != null)
                {
                    title = Convert.ToString(Session["SearchTitle"]);
                }
                BindVideo(title);
            }
        }

        protected void BindVideo(string title)
        {
            IList<Models.VideoInfo> video = VideoInfoManager.GetVideoInfosByTitle(title);
            this.AspNetPager1.RecordCount = video.Count;
            this.AspNetPager1.PageSize = 18;
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = video;
            pds.AllowPaging = true;
            pds.PageSize = 18;
            pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
            Repeater1.DataSource = pds;
            Repeater1.DataBind();
        }

        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            BindVideo(txtSearch.Text.Trim());
        }

        protected string GetPoint(int id)
        {
            string point = "";
            Models.VideoInfo info = VideoInfoManager.GetVideoInfoByID(id);
            if (info.Point == 0)
            {
                point = Convert.ToSingle((VideoPointManager.GetVideoPointsSumByVideoID(id) / VideoPointManager.GetVideoPointsCountByVideoID(id))).ToString("0.0");
                if (point.Equals("非数字"))
                {
                    point = "0";
                }
            }
            else
            {
                point = info.Point.ToString("0.0");
            }
            return point;
        }


        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            BindVideo(txtSearch.Text.Trim());
        }
    }
}
